package com.shaoshaohuo.app.ui;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.shaoshaohuo.app.R;
import com.shaoshaohuo.app.framework.ActivityCollector;
import com.shaoshaohuo.app.framework.SharedPreferencesHelper;
import com.shaoshaohuo.app.ui.fragment.CarDriverFramgment;
import com.shaoshaohuo.app.utils.im.IMFactory;
import com.umeng.analytics.MobclickAgent;

import java.util.ArrayList;
import java.util.List;

/**
 * 司机界面
 * Created by Administrator on 2017/6/25.
 */

public class CarDriver extends BaseActivity {

    private TabLayout ac_cardriver_tab;
    private TextView textView;
    private ViewPager viewPager;
    private List<String> list = new ArrayList<>();
    private List<Fragment> frglist = new ArrayList<>();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ac_cardriverlayout);
        ViewGroup viewById = (ViewGroup) getWindow().getDecorView().findViewById(android.R.id.content);
        changeTransltestaus(viewById.getChildAt(0), this, TransltestausModel.NoePicter, Color.parseColor("#49B152"));
        ac_cardriver_tab = (TabLayout) findViewById(R.id.ac_cardriver_tab);
        viewPager = (ViewPager) findViewById(R.id.ac_cardriver_vp);
        ac_cardriver_tab.setTabMode(TabLayout.MODE_SCROLLABLE);
        ac_cardriver_tab.addTab(ac_cardriver_tab.newTab().setText("未送出"));
        ac_cardriver_tab.addTab(ac_cardriver_tab.newTab().setText("已送出"));
        ac_cardriver_tab.addTab(ac_cardriver_tab.newTab().setText("待退款"));
        list.add("未送出");
        list.add("已送出");
        list.add("待退款");
        textView = (TextView) findViewById(R.id.tv_back);
        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SharedPreferencesHelper.setBoolean(getApplicationContext(),
                        SharedPreferencesHelper.Field.IS_COME_BACK, false);
                ActivityCollector.finishAll();
                Intent intent = new Intent(CarDriver.this, LoginActivity.class);
                intent.putExtra(LoginActivity.TAG_IS_CAN_NOT_BACK, true);
                startActivity(intent);
                IMFactory.logout();
                MobclickAgent.onProfileSignOff();
            }
        });
        Myadapter myadapter = new Myadapter(getSupportFragmentManager());
        viewPager.setAdapter(myadapter);
        ac_cardriver_tab.setupWithViewPager(viewPager);

        frglist.add(CarDriverFramgment.newInstance(0));
        frglist.add(CarDriverFramgment.newInstance(1));
        frglist.add(CarDriverFramgment.newInstance(2));
    }

    class Myadapter extends FragmentPagerAdapter {

        public Myadapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int i) {
            return frglist.get(i);
        }

        @Override
        public int getCount() {
            return list.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return list.get(position);
        }
    }
}
